第 4 步:现在让我们形成一个字符串以打印出来,该字符串将在列表的每个索引处显示等级。

字符串格式化允许使用{花括号}将变量放置在字符串中的特定位置。

  • ,将Insert Two Values拖入print_grades() 。制作字符串"grades[{}] = {}"
  • .format()的括号内,将两个变量替换为indexgrade
  • .format()将第一个{}替换为其第一个参数,将下一个{}替换为下一个参数。

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)